/*
实现redissubscribe.jpg所述
*/
// eslint-disable-next-line @typescript-eslint/no-var-requires
const redis = require('redis')
const client1 = redis.createClient(6379, '127.0.0.1')
const client2 = redis.createClient(6379, '127.0.0.1')
const count = 0
client1.subscribe('food')
client1.subscribe('drink')
client1.on('message', function (channel, message) {
  console.log(channel, message)
  //接受到一个消息就就取消订阅food频道
  client1.unsubscribe('food')
})

client2.publish('food', '面包')
client2.publish('drink', '桔汁')
setTimeout(() => {
  client2.publish('food', '面包2')
  client2.publish('drink', '桔汁2')
}, 2000)
